package com.abc.springboot.controller;


import com.abc.springboot.pojo.User;
import com.abc.springboot.service.UserService;
import com.abc.springboot.service.impl.UserServiceImpl;
import com.abc.springboot.util.LoginData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;


    @RequestMapping("/selectUsers")
    public List<User> selectUsers(){
        return userService.queryUsers();
    }
    //localhost:8090/user/loginVerification?account=xxx
    @RequestMapping("/loginVerification")
    public int loginVerification(@Valid @RequestBody LoginData loginData){
        return userService.loginVerify(loginData.getAccount(),loginData.getPassword());
    }

    @RequestMapping("/query/{phonenumber}")
    public User queryUserByPhonenumber(@PathVariable("phonenumber") long phonenumber){
        return userService.queryUserByAccount(phonenumber);
    }

    @RequestMapping("/enrollUser")
    public boolean enrollUser(@RequestBody User user){
        userService.addUser(user);
        return true;
    }

    @RequestMapping("/updateUserByPhonenumber")
    public int updateUserByPhonenumber(@Valid @RequestBody User user){
        return userService.updateUserByPhonenumber(user);
    }

    @RequestMapping("/updatePassword")
    public int updatePassword(@RequestBody User user){
        return userService.updateUserPassword(user);
    }
}
